<template>
  <!-- 此支付回调页面已经弃用--软糖 -->
  <div class="page content">
    <div v-if="loading">
      <div class="completion">
        <Icon size="60" color="#19be6b" type="ios-checkmark-circle" />
        <span class="text" v-if="orderStatus == 'Recharge'">{{ $t("pay.rechargeSuccessfully") }}</span>
        <span class="text" v-else>{{ $t("pay.paymentSuccess") }}</span>
      </div>
      <span class="text" v-if="orderStatus == 'Recharge'">{{ $t("pay.depositSuccessfullyToppedUp") }}</span>
      <span class="text" v-else-if="orderStatus == 'WAIT_PACK'">{{ $t("pay.parcelDelivery") }}</span>
      <span class="text" v-else-if="orderStatus == 'WAIT_SHIPPING'">{{ $t("pay.parcelDeliveryShipping") }}</span>
      <span class="text" v-else>{{ $t("pay.ordersWillProcessed") }}</span>
      <div class="hint-list">
        <div class="title">{{ $t("pay.noteFollowing") }}:</div>
        <div class="hint-item">
          <div class="hint-item-top">
            <div class="num">1</div>
            <span class="text" v-if="orderStatus == 'WAIT_PACK'">{{ $t("pay.advancePaymentForWaybill") }}</span>
            <span class="text" v-else-if="orderStatus == 'WAIT_SHIPPING'">{{ $t("pay.followShipping") }}</span>
            <span class="text" v-else>{{ $t("pay.goodsWill") }}</span>
          </div>
          <div class="hint-item-content">
            {{ orderStatus == "WAIT_PACK" ? $t("pay.currentPayment") : orderStatus == 'WAIT_SHIPPING' ?
              $t("pay.currentPaymentShipping") : $t("pay.userCenterMyWarehouse") }}
          </div>
        </div>
        <div class="hint-item" v-if="orderStatus != 'WAIT_SHIPPING'">
          <div class="hint-item-top">
            <div class="num">2</div>
            <span class="text">{{ orderStatus == "WAIT_PACK" ? $t("pay.followTheWaybill") : $t("pay.attentionOrder")
            }}</span>
          </div>
          <div class="hint-item-content">
            {{ orderStatus == "WAIT_PACK" ? $t("pay.waybillProcessing") : $t("pay.attentionOrder") }}
          </div>
        </div>
      </div>
      <div class="footer">
        <router-link :to="'/transport/roam?id=' + $route.query.orderNo" v-if="orderStatus == 'WAIT_PACK'">
          <Button class="btn" type="success">{{ $t("pay.see") }}</Button>
        </router-link>
        <router-link :to="'/transport/roam?id=' + $route.query.orderNo" v-else-if="orderStatus == 'WAIT_SHIPPING'">
          <Button class="btn" type="success">{{ $t("pay.continueShipping") }}</Button>
        </router-link>
        <router-link to="/" v-else>
          <Button class="btn" type="success">{{ $t("pay.continueShopping") }}</Button>
        </router-link>
        <router-link to="/user/warehouse" v-if="orderStatus == 'WAIT_PACK'">
          <Button class="btn" type="success">{{ $t("pay.continue") }}</Button>
        </router-link>
        <router-link to="/user/shipment" v-else-if="orderStatus == 'WAIT_SHIPPING'">
          <Button class="btn" type="success">{{ $t("user.myWaybill") }}</Button>
        </router-link>
        <router-link to="/user/warehouse" v-else-if="orderNoCharAt == 'B'">
          <Button class="btn" type="success" ghost>{{ $t("pay.viewOrder") }}</Button>
        </router-link>
        <router-link to="/user/order" v-else>
          <Button class="btn" type="success" ghost>{{ $t("pay.viewOrder") }}</Button>
        </router-link>
      </div>
    </div>
    <grand-prize ref="grandRef" :activityId="activityId"></grand-prize>
  </div>
</template>

<script>
import { orderQuery } from "@/api/order";
import { searchOrderFirst, lotteryClick } from "@/api/expressOrder";
import grandPrize from '../activity/freeShipping/components/grand-prize.vue';
export default {
  components: { grandPrize },
  name: "completion",
  data() {
    return {
      type: "",
      orderNo: "",
      orderStatus: "",
      loading: false,
      orderNoCharAt: '',
      activityId: ''
    };
  },
  created() {
    let orderNoCharAt = this.$route.query.orderNo.charAt(0);
    this.orderNoCharAt = orderNoCharAt;
    this.orderStatus = orderNoCharAt == "R" ? "Recharge" : "";
    if (this.$route.query.orderNo && orderNoCharAt == 'Y') {
      orderQuery({
        orderNo: this.$route.query.orderNo,
      }).then((res) => {
        this.orderStatus = res.result.status;
        this.loading = true;
      });
    } else this.loading = true;


    // 是否运单首单
    const orderNo = this.$route.query.orderNo;
    if (orderNo && orderNo.startsWith('Y')) {
      this.searchResult();
    }
  },
  methods: {
    confirmPay() {
      this.$router.push("/user/center");
    },
    searchResult() {
      searchOrderFirst(this.$route.query.orderNo).then((res) => {
        if (res.result.activityId) {
          this.activityId = res.result.activityId;
          this.$refs.grandRef.open('resultPop');
          this.clickSave(res.result.activityId);
        }
      })
    },
    clickSave(activityId) {
      lotteryClick({ activityId: activityId, operateType: 1 });
    }
  },
};
</script>

<style scoped lang="less">
.content {
  background: none !important;
}

.page {
  width: 1200px;
  margin: 50px auto;

  .completion {
    display: flex;
    align-items: center;

    .text {
      display: block;
      text-align: center;
      color: @success-color;
      font-size: 18px;
      font-weight: 600;
    }
  }

  .text {
    color: @t-text-color;
    font-size: 14px;
  }

  .hint-list {
    .title {
      margin-top: 46px;
      color: @t-title-color;
      font-size: 20px;
      font-weight: bold;
    }

    .hint-item {
      margin-top: 24px;

      &-top {
        display: flex;
        align-items: center;

        .num {
          display: flex;
          align-items: center;
          justify-content: center;
          width: 20px;
          height: 20px;
          margin-right: 6px;
          border-radius: 50%;
          background: @success-color;
          color: #ffffff;
          font-size: 14px;
          font-weight: 500;
        }

        .text {
          color: @t-title-color;
          font-size: 14px;
          font-weight: 500;
        }
      }

      &-content {
        padding: 12px 0;
        color: @t-text-color;
        font-size: 14px;
      }
    }
  }

  .hint {
    display: block;
    text-align: center;
    color: @t-text-color;
    font-size: 14px;
  }

  .footer {
    margin-top: 24px;

    .btn {
      margin-right: 12px;
    }
  }
}
</style>
